package engine

import (
	"encoding/json"
	"io"
	"miniDW/src/log"
	"os"
)

type ConfigInfo struct {
	Name     string
	Kind     string
	Operator string
	Provider string
	Sources  []string
	Targets  []string
	Table    interface{}
	Params   map[string]interface{}
}

func LoadCfgFile(path string) ([]ConfigInfo, error) {
	file, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer func(file *os.File) {
		err := file.Close()
		if err != nil {
			_ = log.Error(err)
		}
	}(file)

	raw, err := io.ReadAll(file)
	if err != nil {
		return nil, log.Error(err)
	}

	var data []ConfigInfo
	err = json.Unmarshal(raw, &data)
	if err != nil {
		return nil, log.Error(err)
	}
	return data, nil
}
